﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        private int currentComPort;
        public Form1()
        {
            InitializeComponent();
            //comSelector = new ComboBox();
            comSelector.Items.AddRange(SerialPort.GetPortNames());
            //comSelector.TabIndex = SerialPort.GetPortNames().Length;
        }

        

        private void button1_Click(object sender, EventArgs e)
        {

            StringBuilder buffer = new StringBuilder();
            String[] ports = SerialPort.GetPortNames();
            serialPort communication = new serialPort(ports[currentComPort]);
            foreach(String item in ports){
                buffer.Append(item).Append("\r\n");
            }




            displayBox.Text = buffer.ToString();
            communication.write();
            displayBox.Text = communication.getBuffer();
        }

        private void displayBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void comSelector_SelectedIndexChanged(object sender, EventArgs e)
        {
            currentComPort = comSelector.SelectedIndex;
        }
    }
}
